Skip to content

fix(connectors): follow-up hardening for callApi - #261

Merged
ChenMachBase merged 1 commit into
mainfrom
connectors-followup-fixes
Aug 26, 2026
Merged

fix(connectors): follow-up hardening for callApi#261
ChenMachBase merged 1 commit into
mainfrom
connectors-followup-fixes

Conversation

@ChenMachBase

Copy link
Copy Markdown
Contributor

Follow-up to #256, addressing the review findings that were worth fixing post-merge.

Changes

  • Percent-encode caller-supplied identifiers in request URLs. callApi (and the sibling connector methods, which shared the pattern) interpolated the integration type / connector ID into the URL unencoded, so a runtime-built string containing ../ could re-target a different API route while carrying the service-role token. Identifiers are now confined to their path segment. Covered by a new unit test.
  • ConnectorApiResponse.data is now T | null. The JSDoc and the implementation already returned null for binary responses (and proxy error details on failure), but an explicit type argument produced a non-nullable type that ends in a runtime TypeError. Fixing this now, before external TS consumers depend on the old signature, keeps it from becoming a breaking change later. Covered by new type-contract assertions.
  • host: null is treated as unset. The omission check was === undefined, so untyped JS callers writing host: x ?? null sent a literal "host": null to the proxy, defeating the default-host fallback. Now checked with == null. Covered by a new test case.
  • nock.disableNetConnect() in the proxy tests. The new test file was the only one missing it, so an interceptor mismatch escaped as a real HTTPS request to production instead of failing fast.
  • CI now runs npm run test:types. The type-contract tests added in feat(connectors): callApi for metered connectors #256 (including this PR's new assertions) were never enforced — no workflow invoked them.

Testing

  • npm run test:types — clean
  • npm run test:unit — 223/223 passing

🤖 Generated with Claude Code

- Percent-encode caller-supplied integration types and connector IDs in
  request URLs, so a runtime-built identifier can only select a
  connector, never re-target another route under the privileged token
- Type ConnectorApiResponse.data as T | null to match the documented
  and implemented contract (null for binary and proxy-error responses)
- Treat host: null like undefined when omitting the host field, since
  untyped callers write `host: x ?? null`
- Add nock.disableNetConnect() to the proxy tests so interceptor
  mismatches fail fast instead of escaping as real network requests
- Run test:types in CI so the type-contract tests are enforced

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.8.43-pr.261.f8cbcf8

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.43-pr.261.f8cbcf8"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.8.43-pr.261.f8cbcf8"
  }
}

Preview published to npm registry — try new features instantly!

@github-actions github-actions Bot added the docs-draft PR has auto-drafted documentation suggestions label Aug 26, 2026
@ChenMachBase
ChenMachBase merged commit 7b66851 into main Aug 26, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-draft PR has auto-drafted documentation suggestions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants